Skip to content

[hsskey] WEEK 1 solutions #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 5, 2025
Merged

[hsskey] WEEK 1 solutions #1168

merged 6 commits into from
Apr 5, 2025

Conversation

hsskey
Copy link
Member

@hsskey hsskey commented Apr 1, 2025

답안 제출 문제

작성자 체크 리스트

  • 우측 메뉴에서 PR을 Projects에 추가해주세요.
  • Projects의 오른쪽 버튼(▼)을 눌러 확장한 뒤, Week를 현재 주차로 설정해주세요.
  • 문제를 모두 푸시면 프로젝트에서 StatusIn Review로 설정해주세요.
  • 코드 검토자 1분 이상으로부터 승인을 받으셨다면 PR을 병합해주세요.

검토자 체크 리스트

Important

본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!

  • 바로 이전에 올라온 PR에 본인을 코드 리뷰어로 추가해주세요.
  • 본인이 검토해야하는 PR의 답안 코드에 피드백을 주세요.
  • 토요일 전까지 PR을 병합할 수 있도록 승인해주세요.

@hsskey hsskey added the js label Apr 1, 2025
@hsskey hsskey changed the title contains-duplicate solved [hsskey] WEEK 1 solutions Apr 1, 2025
@hsskey hsskey marked this pull request as ready for review April 1, 2025 12:49
@lhc0506 lhc0506 self-requested a review April 1, 2025 13:15
@hsskey hsskey moved this from Solving to In Review in 리트코드 스터디 4기 Apr 4, 2025
Copy link
Contributor

@lhc0506 lhc0506 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map과 set을 너무 잘 사용하시고, 코드도 깔끔하고 읽기 쉽게 작성하십니다 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

num - 1을 확인해서 시작이 되는 값을 찾는 것이 좋은것같습니다!

발상은 비슷한데 조금 다른 제 방식은 num에서 while을 +1로도 가고, -1 로도 가게했습니다. 그리고 각각 반복할 때, numSet에서 currentNum을 지워주구요!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다른 관점에서 생각못해본 부분인데 피드백 감사합니다.
처음 아이디어를 떠올릴땐, 좌표선상에 연속된 sequence 그룹을 펼쳐놓았을때,
해당 그룹들의 이전 이웃값(n-1)이 없을때 sequence 그룹을 만들 수 있겠다 생각해서 표현해놓은 부분입니다.

말씀해주신대로 while문에서 +1이나 -1로도 가게할 수도 있군요👍

Comment on lines +9 to +16
for(let i = 0; i < nums.length; i++) {
if(map.has(nums[i])) {
const prevVal = map.get(nums[i])
map.set(nums[i], prevVal + 1)
} else {
map.set(nums[i], 1)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(개인적인 생각입니다)
아래 코드에서는 Array메서드를 사용하여 명시적으로 해주셔서 여기도 forEach로 사용하는게 조금 더 통일성이 있을 것 같습니다!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋은 피드백 감사합니다 🙇‍♂️
말씀해주신 것처럼 forEach를 쓰면 코드가 더 간결하고 Array 메서드 체이닝과도 일관성이 생길 수 있다는 점 공감합니다.

다만 저는 반복문 처리에서의 미세한 성능 차이를 고려해서 for 루프를 선호하는 편입니다. (주로 실무에서도)
특히 입력 배열이 커질 경우 forEach의 콜백 호출 비용이 누적될 수 있고, break/continue 등의 흐름 제어가 제한되는 점도 고려하고 있습니다.

물론 이번 문제에선 실제 성능 차이는 거의 없겠지만, 개인적으로는 성능 상 이점을 조금이라도 취할 수 있는 구조를 습관화하는 쪽을 택하고 있습니다.

다시 한 번 스타일 일관성에 대한 피드백 감사드려요. 더 고민해볼 수 있는 좋은 계기가 됐습니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기는 제가 아직 안풀어서 우선 approve 하고 추후 확인하겠습니다.

* @return {number}
*/
var rob = function(nums) {
if (nums.length === 0) return 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 당연히 length는 0이 아니겠지하고 조건을 안보고 진행했었는데 이부분 까지 꼼꼼하게 생각하신점이 좋습니다👍
(저한테는 다행히 조건에 1 <= nums.length <= 100 가 있어서 통과가 된것같네요.)

@hsskey
Copy link
Member Author

hsskey commented Apr 5, 2025

@lhc0506 꼼꼼한 리뷰 감사합니다
리뷰 피드백 확인완료하고 merge합니다.

@hsskey hsskey merged commit 293da73 into DaleStudy:main Apr 5, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In Review to Completed in 리트코드 스터디 4기 Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

2 participants